<template>
	<view class="content">
		<view class="status_bar barcolor"></view>
		<video id="myVideo" class="videoplay" autoplay="true" :src="movieInfo.movieUrl" @error="videoErrorCallback"
			controls></video>

		<view class="movieinfo">
			<u-image width="255rpx" height="350rpx" border-radius="5" :src="$mConfig.formatFileUrl(movieInfo.cover)">
			</u-image>

			<view class="movieinfo-right">
				<text class="title">{{movieInfo.movieName}}</text>
				<text class="subtitle">{{movieInfo.info}}</text>
				<text class="subtitle">{{movieInfo.originaName}}</text>
				<text class="subtitle">影片时长：{{movieInfo.totalTime}}</text>
				<text class="subtitle">上映时间：{{movieInfo.releaseDate}}</text>

				<view class="zenghepingfen">

					<view class="zenghepingfen-left">
						<text class="zenghepingfen-title">综合评分:</text>
						<text class="zenghepingfen-title2">{{movieInfo.score}}</text>

					</view>

					<view class="zenghepingfen-right">
						<u-rate current="3.7" active-color="#6495ED" size="12" gutter="2" :disabled="true"></u-rate>
						<text class="zenghepingfen-title">{{movieInfo.counts}}人点赞</text>
					</view>
				</view>
			</view>

		</view>

		<view class="bottom-view">
			<text class="bottom-title">剧情介绍</text>
			<text class="bottom_content">{{movieInfo.plotDesc}}</text>
			<text class="bottom-title">演职人员</text>
			<scroll-view class="yanzhirenyuan-scroll" scroll-x="true">
				<view class="yanzhirenyuan-item" v-for="(item,index) in movieInfo.plotsWords" :key="index"
					@click="previewYanyuanImas(movieInfo.plotsWords,item.imgUrl)">
					<u-image width="100%" height="290rpx" :src="$mConfig.formatFileUrl(item.imgUrl)" mode="scaleToFill"
						border-radius="10"></u-image>
					<text class="title">{{item.actorRole}}:{{item.autor}}</text>
				</view>
			</scroll-view>
			<text class="bottom-title">剧照</text>
			<scroll-view class="yanzhirenyuan-scroll" scroll-x="true">
				<view class="yanzhirenyuan-item" v-for="(item,index) in movieInfo.plotsImg" :key="index"
					@click="previewYanyuanImas(movieInfo.plotsImg,item.imgUrl)">
					<u-image width="100%" height="290rpx" :src="$mConfig.formatFileUrl(item.imgUrl)" mode="scaleToFill"
						border-radius="10"></u-image>
				</view>
			</scroll-view>

			<text class="bottom-title">热门评论</text>
			<view class="comments-item" v-for="(item,index) in comments" :key="index">
				<view class="comments-item-top">
					<u-image width="40rpx" height="40rpx" border-radius="20"
						:src="$mConfig.formatFileUrl(item.headicon)">
					</u-image>
					<text class="comments-item-title">{{item.nickname}}</text>
				</view>
				<text class="comments-item-content">{{item.content}}</text>
				<text class="comments-item-date">{{item.startTime}}</text>

			</view>
		</view>



		<view class="btn_group">

			<image class="btn_dian" src="../../static/img/movieinfo_dianzan.png" @click="dianzan" mode="scaleToFill">
			</image>
			<image class="btn_dian" :src="getShoucangIcon()" @click="shoucang" mode="scaleToFill">
			</image>
			<image class="btn_dian" src="../../static/img/movieinfo_pinglun.png" @click="pinglun" mode="scaleToFill">
			</image>

		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				movieInfo: {},
				movieId: "",
				comments: [],
				videoContext: ""
			}
		},
		onLoad(res) {
			this.movieId = res.movieId;
			this.requesData();
		},
		onReady() {
			this.videoContext = uni.createVideoContext("myVideo")
		},
		onShow() {
			this.requestComments();
		},
		onHide() {
			if (this.videoContext) {
				this.videoContext.pause();
			}
		},
		methods: {
			videoErrorCallback: function(e) {
				// uni.showModal({
				// 	content: e.target.errMsg,
				// 	showCancel: false
				// })
			},
			requesData() {
				//获取影片详情
				this.$u.get('/client/movies/info', {
					'movieId': this.movieId
				}).then(res => {
					this.movieInfo = res.item;
				});
			},
			requesLikes() {
				//给电影点赞
				this.$u.post('/client/movies/likes', {
					'movieId': this.movieId
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '点赞成功',
							duration: 2000,
							icon: 'none',
							position: 'bottom'
						});
						//点赞成功后，刷新页面
						this.requesData()
					}
				});
			},
			requestCollec() {
				//收藏电影
				this.$u.post('/client/collections/postcolle', {
					'movieId': this.movieId,
					'type': this.movieInfo.iscollec === '0' ? '1' : '2'
				}).then(res => {
					let tips = '收藏成功'
					if (this.movieInfo.iscollec === '1') {
						tips = '取消成功';
					}
					if (res.code == 200) {
						uni.showToast({
							title: tips,
							duration: 2000,
							icon: 'none',
							position: 'bottom'
						});
						//收藏成功后，刷新页面
						this.requesData()
					}
				});
			},
			requestComments() {
				//获取电影的评论列表
				this.$u.post('/client/comments/commentlist', {
					'movieId': this.movieId,
				}).then(res => {
					this.comments = res.list;
				});
			},
			getShoucangIcon() {
				if (!this.movieInfo) {
					return '../../static/img/movieinfo_shoucang.png'
				} else if (this.movieInfo.iscollec === '0') {
					return '../../static/img/movieinfo_shoucang.png'
				} else {
					return '../../static/img/movieinfo_shoucang_p.png'
				}

			},
			dianzan() {
				this.requesLikes()
			},
			shoucang() {
				this.requestCollec()
			},
			pinglun() {
				uni.navigateTo({
					url: '../sendcomment/sendcomment?movieId=' + this.movieId
				})
			},
			previewYanyuanImas(imgarr, imgurl) {
				const urls = imgarr.map(item => {
					return this.$mConfig.formatFileUrl(item.imgUrl);
				})
				uni.previewImage({
					current: this.$mConfig.formatFileUrl(imgurl),
					urls: urls,
					indicator: "number",
					loop: true
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f9f9f9;
	}

	.barcolor {
		background-color: #000000;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.videoplay {
		width: 100%;
		margin-top: -2rpx;
	}

	.movieinfo {
		display: flex;
		padding: 30rpx 25rpx 35rpx 25rpx;
		width: 100%;
		flex-direction: row;
		border-bottom: 1rpx solid #dddddd;

		.movieinfo-right {
			display: flex;
			margin-left: 25rpx;
			flex: 1;
			flex-direction: column;

			.title {
				font-size: 19px;
				color: $uni-text-color;
				margin-bottom: 5rpx;
				font-weight: bold;
			}

			.subtitle {
				margin-top: 8rpx;
				font-size: 12px;
				color: #666666;

			}

			.zenghepingfen {
				margin-top: 20rpx;
				background-color: $uni-bg-color;
				padding: 20rpx;
				display: flex;
				box-shadow: 5px 5px 10px #cccccc;
				flex-direction: row;

				.zenghepingfen-left {
					display: flex;
					flex-direction: column;
					align-items: center;

					.zenghepingfen-title {
						font-size: 12px;
						color: #666666;
					}

					.zenghepingfen-title2 {
						font-size: 17px;
						font-weight: bold;
						color: $uni-color-primary;
					}
				}


				.zenghepingfen-right {
					display: flex;
					margin-left: 30rpx;
					flex-direction: column;

					.zenghepingfen-title {
						font-size: 9px;
						color: #666666;
					}
				}
			}
		}
	}

	.bottom-view {
		display: flex;
		flex-direction: column;
		width: 100%;
		padding: 25rpx;

		.bottom-title {
			font-size: 14px;
			color: $uni-text-color-grey;
		}

		.bottom_content {
			margin-top: 10rpx;
			font-size: 13px;
			line-height: 18px;
			margin-bottom: 25rpx;
		}

		.yanzhirenyuan-scroll {
			margin-top: 15rpx;
			width: 100%;
			margin-bottom: 25rpx;
			white-space: nowrap;

			.yanzhirenyuan-item {
				display: inline-flex;
				width: 220rpx;
				flex-direction: column;
				margin-right: 15rpx;

				.title {
					margin-top: 10rpx;
					font-size: 15px;
					color: $uni-text-color;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
		}

		.comments-item {
			padding-top: 20rpx;
			padding-bottom: 20rpx;
			display: flex;
			border-bottom: #eee dashed 1px;
			flex-direction: column;

			.comments-item-top {

				display: flex;
				align-items: center;
				flex-direction: row;

				.comments-item-title {
					margin-left: 10rpx;
					font-size: 14px;
				}
			}

			.comments-item-content {
				font-size: 13px;
				margin-top: 12rpx;
				line-height: 19px;
				margin-bottom: 10rpx;
				color: $uni-text-color;
			}

			.comments-item-date {
				font-size: 11px;
				color: $uni-text-color-grey;
			}
		}
	}

	.btn_group {
		display: flex;
		flex-direction: column;
		width: 85rpx;
		height: 260rpx;
		background-color: rgba(255, 255, 255, 0.8);
		border-radius: 15rpx;
		box-shadow: 0px 0px 5px #888888;
		position: fixed;
		bottom: 60rpx;
		right: 50rpx;
		justify-content: space-around;
		align-items: center;

		.btn_dian {
			width: 52rpx;
			height: 52rpx;
		}
	}
</style>
